/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025/5/23
 * Time: 21:36
 */

public class Solution {
    public static TreeNode sortedArrayToBST(int[] nums) {
        return sortedArrayToBST2(nums, 0, nums.length - 1);
    }
    public static TreeNode sortedArrayToBST2(int[] nums,int start,int end) {
        if (start > end) {
            return null;
        }
        int mid = (start + end) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = sortedArrayToBST2(nums, start, mid - 1);
        root.right = sortedArrayToBST2(nums, mid + 1, end);
        return root;
    }
    public static void main(String[] args) {
        System.out.println(sortedArrayToBST(new int[]{-10, -3, 0, 5, 9}));
    }
}